<template>
	<view class="business-credentials-main">
		<view class="job-box">
			<view class="tit">公司全称</view>
			<view class="item-box">
				<view :class="{'tips-txt': !detail.full_name}">
					<input class="input-this" placeholder="请输入公司全称" :disabled="detail.state == 1" v-model="detail.full_name" data-key="full_name"
					 maxlength="42"></input>
				</view>
			</view>
		</view>
		<view class="job-box">
			<view class="tit">公司法人</view>
			<view class="item-box">
				<view :class="{'tips-txt': !detail.legal}">
					<input class="input-this" placeholder="请输入公司法人" :disabled="detail.state == 1" v-model="detail.legal" data-key="legal"
					 maxlength="24"></input>
				</view>
			</view>
		</view>
		<view class="job-box">
			<view class="tit">注册时间</view>
			<picker mode="date" fields="month" data-key="reg_time" :disabled="detail.state == 1" :value="detail.reg_time"
			 @change="onPickerChange">
				<view :class="{'time time-right': true, 'tips-txt': !detail.reg_time}">{{ detail.reg_time || '请选择注册时间' }}</view>
			</picker>
		</view>
		<view class="job-box">
			<view class="tit">注册资本(万元)</view>
			<view class="item-box">
				<view :class="{'tips-txt': !moreDemand}">
					<input class="input-this" placeholder="请输入注册资本" :disabled="detail.state == 1" v-model="detail.capital" data-key="capital"
					 maxlength="16"></input>
				</view>
			</view>
		</view>
		<btnTpl v-if="detail.state != 1 && detail.state != 3" @confirmEvent="checkThreeLevelFn">保存</btnTpl>
	</view>
</template>

<script>
	import {
		upAuthenticationSrv
	} from '../../../apis/recruit/index.js'
	import btnTpl from '../../components/recruit/btn-tpl.vue'

	export default {
		data() {
			return {
				detail: {
					reg_time: '',
					full_name: '',
					legal: '',
					capital: ''
				},
				rules: {
					full_name: [{
							required: true,
							message: '请输入公司全称',
						},
						{
							min: 2,
							max: 30,
							message: '公司全称字符长度在 2 到 30 个字符',
						}
					],
					legal: [{
						required: true,
						message: '请输入公司法人',
					}, {
						min: 2,
						max: 20,
						message: '法人字符长度在 2 到 20 个字符',
					}],
					reg_time: [{
						required: true,
						message: '请选择注册时间',
					}],
					capital: [{
						required: true,
						message: '请输入注册资本',
					}, {
						isNumber: true,
						message: '注册资本必须是数字',
					}, {
						min: 1,
						max: 10,
						message: '注册资本字符长度在 1 到 10 个字符',
					}],
				}
			}
		},
		onLoad(options) {
			this.detail = uni.getStorageSync('authentication')
		},
		components: {
			btnTpl
		},
		methods: {
			checkThreeLevelFn() {
				let _this = this;
				let params = _this.detail
				delete params.state
				this.$verification(params, _this.rules, ok => {
					upAuthenticationSrv(params).then(res => {
						if (res.code == 1) {
							uni.navigateBack({
								delta: 1 // delta: 1返回上一级（A 页面）    delta: 2返回上两级
							})
						}
					})
				})

			},
			/**
			 * 日历控件绑定函数 
			 * 点击日期返回
			 */
			onPickerChange(e) {
				let key = e.currentTarget.dataset.key,
					value = e.detail.value
				this.detail[key] = value
			},
		}
	}
</script>

<style lang="less">
	.business-credentials-main {
		padding: 0 30rpx;
	}

	.job-box {
		padding: 38rpx 0 0;
		box-shadow: 0 1rpx 0.5rpx -1rpx #CCCCCC;
	}

	.job-box .tit {
		font-size: 24rpx;
		line-height: 24rpx;
	}

	.job-box .item-box {
		font-size: 30rpx;
		line-height: 30rpx;
		padding: 15rpx 0 20rpx;
	}

	.job-box picker {
		font-size: 30rpx;
		line-height: 30rpx;
		padding: 20rpx 0 30rpx;
	}

	.job-box .item-box .input-this {
		font-size: 30rpx;
	}
</style>
